import requests
import re

"""
    爬取景区的天气预告
"""


# 定义函数
def get_html():
    url = 'https://qq.weather.com.cn/mweather15d/10119010121A.shtml'
    # 打开浏览器并打开网址
    resp = requests.get(url)
    # 设置一下编码格式
    resp.encoding = 'utf-8'
    # resp响应对象， 对象名.属性名  resp.text
    return resp.text


def parse_html(html_str):
    # <p class="h15listdayp2">10/07</p>
    # <p>多云转阴</p>
    # <div class="h15listtem h15k" style="">30/22℃</div>
    # <td><div>东南风3-4级</div>
    # <div>东风<3级</div></td>

    date = re.findall('<p class="h15listdayp2">(.*)</p>', html_str)
    tq = re.findall('<p>([\u4e00-\u9fa5]*)</p>', html_str)
    wd = re.findall('<div class="h15listtem h15k" style="">(.*)</div>', html_str)
    feng1 = re.findall('<td>\n<div>(.*)</div>', html_str)
    feng2 = re.findall('<div>(.*)</div>\n</td>', html_str)

    # print(date)
    # print(tq)
    # print(wd)
    # print(feng1)
    # print(feng2)

    lst = []
    for a, b, c, d, e in zip(date, tq, wd, feng1, feng2):
        lst.append([a, b, c, d, e])

    for item in lst:
        print(item)

    return lst

